package com.goldsprite.microhorigame.ecs.fsms.states;

import com.goldsprite.gameframeworks.log.Debug;

public class EntityJumpState extends EntityState {
	boolean isJumped;
	boolean isOnWall,isKeyJumpUp;//用于解决蹭墙连跳

		@Override
		public boolean canEnter() {
			return fsm.getInputs().getKeyJump() && fsm.getFootTrigger().isGround();
		}

		@Override
		public boolean canExit() {
			return fsm.getRigi().getVelocity().y <= 0;
		}

		@Override
		public void enter() {
			isJumped = false;
			isKeyJumpUp = false;
			fsm.getAnims().playAnim("Jump", true);
			//跳跃力
			if (!fsm.isFalling()) fsm.getProps().jump();
		}

		@Override
		public void running() {
			//切换跳跃与下落动画
			boolean isFalling = fsm.isFalling();
			//持续更新速度与朝向
			fsm.getProps().move(fsm.getInputs().getKeyDirX());
			
//			//贴墙且手臂高度不超出墙的高度
//			if(fsm.getBodyCollider().isCollision("Ground")){
//				Debug.log("碰撞墙, 跌落: %s", isFalling);
//				fsm.getAnims().playAnim("WallSlide");
//				if(isFalling)
//					fsm.getRigi().setVelocity(fsm.getRigi().getVelocity().x, 0);
//			}else{
//				fsm.getAnims().playAnim(isFalling ? "Fall" : "Jump");
//			}
//			//是否松手
//			if(!fsm.getInputs().getKeyJump())
//				isKeyJumpUp = true;
//			//已离开地面或身体有接触点(碰撞)则标记已起跳
//			if (!fsm.isGround() || fsm.getBodyCollider().isCollision()) isJumped = true;
//			//蹭墙跳
//			if (!isOnWall && fsm.getBodyCollider().isCollision() && isKeyJumpUp && fsm.getInputs().getKeyJump()) {
//				fsm.getProps().jump();
//				isOnWall = true;
//				isKeyJumpUp = false;
//			}
//			if (isOnWall && !fsm.getBodyCollider().isCollision()){
//				isOnWall = false;
//			}
		}
	}
